﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Text;
using Eis51.CampanyCMS.Model.NewsManager.QueryO;
using Eis51.CampanyCMS.Model;
using Eis51.CampanyCMS.Business.NewsManager;
using Eis51.CampanyCMS.Model.NewsManager;
using System.Collections;

namespace Eis51.Web.dataPage
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class MarketHome : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            StringBuilder sb = new StringBuilder();

            LoadNews(ref sb);

            context.Response.Write("[ " + sb.ToString() + "]");
        }

        private void LoadNews(ref StringBuilder hoemData)
        {
            MarketQuery query = new MarketQuery();
            query.Licd = (Eis51.CampanyCMS.FrameWork.Licd)AppContext.LCID;
            query.IsFist = true;
            IList list = MarketBLL.GetInstance().Search(query);

            //IList list = MarketBLL.GetInstance().Select();
            ShowData model = null;
            Market newsModel = null;
            string tmpStr = string.Empty;
            int count = 9;

            if (null != list && list.Count > 0)
            {
                int i = 0;
                foreach (var et in list)
                {
                    newsModel = (Market)et;
                    i++;
                    if (i > count)
                    {
                        break;
                    }
                    if (string.Empty.Equals(newsModel.Title))
                    {
                        count++;
                        continue;
                    }
                    model = new ShowData { Seqno = newsModel.Seqno, Title = newsModel.Title };
                    tmpStr = Eis51.Web.common.common.JavaScriptSerializerString(model);
                    hoemData.Append(",");
                    hoemData.Append(tmpStr);
                }
                //divContent.InnerHtml = news.Content;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
